#include "mainwindow.h"
#include "ui_mainwindow.h"

#define MESSAGE \
             tr("<a href=\"http://code.google.com/p/pic2lcd/\">PIC2PCD</a> " \
                "is able to extract rgb raw data form any format images. ")


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::on_srcImgBtn_clicked()
{
    if (srcFn.isEmpty())
    {
        // Import Image form running application's directory
        srcFn = QFileDialog::getOpenFileName(this,
                  "Open Image", QCoreApplication::applicationDirPath(),
                  "Image Files (*.bmp *.png *.xpm *.jpg *.gif)");
    }else{
        // Import Image from current directory
        srcFn = QFileDialog::getOpenFileName(this,
                  "Open Image", srcFi.path(),
                  "Image Files (*.bmp *.png *.xpm *.jpg *.gif)");
    }
    // Load Image right now
    ImgImport();
}

void MainWindow::ImgImport()
{

    if(srcFn != NULL)
    {
      ui->srcImgBtn->setText(tr(""));
      ui->desImgBtn->setText(tr(""));

      // Load Image to QImage
      srcImg.load(srcFn);
      desImg = srcImg;

      // Parpare file Info
      srcFi = srcFn;
      desFi = desFn;

      // Processing Image
      ImgProcess();
      // Update to Btn
      //ui->srcImgBtn->setIconSize(QSize(srcImg.width(),srcImg.height()));
      //ui->desImgBtn->setIconSize(QSize(desImg.width(),desImg.height()));
      ui->srcImgBtn->setIcon(QPixmap::fromImage(srcImg));
      ui->desImgBtn->setIcon(QPixmap::fromImage(desImg));

      // Update tooltip
      ui->srcImgBtn->setToolTip(tr("From ") + srcFn + "  ("
                                 + QString::number(srcImg.width())  + ", "
                                 + QString::number(srcImg.height()) + ")");
      ui->desImgBtn->setToolTip(tr("Image Size")    + "  ("
                                   + QString::number(desImg.width())  + ", "
                                   + QString::number(desImg.height()) + ")");

      // Update status bar
      ui->statusBar->showMessage("Load file " + srcFn + " ("
                                 + QString::number(srcImg.width())  + ", "
                                 + QString::number(srcImg.height()) + ")");
    }

}


void MainWindow::ImgProcess()
{
    if (srcFn.isEmpty())
    {
        ui->statusBar->showMessage(tr("Please import an image first"),1000);
    }else{
        ImgProcessResize();
        ImgProcessRotation();
        ImgProcessWatermark();
        ImgProcessReverser();
        ImgProcessBrightness();
        ImgProcessBitsPixel();
    }
}

void MainWindow::ImgProcessResize()
{
    int scaleW = 0;
    int scaleH = 0;
    if (!(ui->ImgWidthEd->text().isEmpty()))
        { scaleW= ui->ImgWidthEd->text().toInt(); }
    if (!(ui->ImgHeightEd->text().isEmpty()))
        { scaleH = ui->ImgHeightEd->text().toInt(); }

    if (scaleW != 0 && scaleH != 0)
        { desImg = srcImg.scaled(scaleW, scaleH, Qt::KeepAspectRatio); }

}

void MainWindow::ImgProcessRotation()
{
    QRgb value;
    QImage tmpImg;
    tmpImg = desImg;
    if (ui->rotationSel->currentText() == "Normal")
    {
        goto exit;
    }else if (ui->rotationSel->currentText() == "Mirror Left-Right")
    {
        for (int dx=0; dx < tmpImg.width(); dx++)
        {
        for (int dy=0; dy < tmpImg.height(); dy++)
            {
            value = tmpImg.pixel(dx ,dy);
            desImg.setPixel(tmpImg.width()-1-dx, dy, value);
            }
        }
    }else if (ui->rotationSel->currentText() == "Mirror Up-Down")
    {
        for (int dx=0; dx < tmpImg.width(); dx++)
        {
        for (int dy=0; dy < tmpImg.height(); dy++)
            {
            value = tmpImg.pixel(dx ,dy);
            desImg.setPixel(dx, tmpImg.height()-1-dy, value);
            }
        }
    }else if (ui->rotationSel->currentText() == "Mirror All")
    {
        for (int dx=0; dx < tmpImg.width(); dx++)
        {
        for (int dy=0; dy < tmpImg.height(); dy++)
            {
            value = tmpImg.pixel(dx ,dy);
            desImg.setPixel(tmpImg.width()-1 - dx,
                            tmpImg.height()-1- dy, value);
            }
        }

    }
exit:
    qDebug()<< "exit ImgProcessRotation";
}
void MainWindow::ImgProcessWatermark()
{
    int x, y;
    int w, h;
    x = ui->watermarkOffsetXspin->value();
    y = ui->watermarkOffsetYspin->value();
    w = desImg.width();
    h = desImg.height();
    QPainter painter(&desImg);

    painter.setFont(desImgFont);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QPen(desImgFontColor, 20, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
    QFontMetrics fm = painter.fontMetrics();

    if (ui->watermarkOffestAlignHozSel->currentText() == tr("Left") &&
        ui->watermarkOffestAlignVerSel->currentText() == tr("Top"))
    {
        x = x;
        y = y + fm.ascent();
    }else if(ui->watermarkOffestAlignHozSel->currentText() == tr("Right") &&
             ui->watermarkOffestAlignVerSel->currentText() == tr("Top"))
    {
        x = w - x - fm.averageCharWidth() * ui->watermarkCharInputLabEd->text().length();
        y = y + fm.ascent();

    }else if(ui->watermarkOffestAlignHozSel->currentText() == tr("Left") &&
             ui->watermarkOffestAlignVerSel->currentText() == tr("Bottom"))
    {
        x = x;
        y = h - y;
    }else if(ui->watermarkOffestAlignHozSel->currentText() == tr("Right") &&
                     ui->watermarkOffestAlignVerSel->currentText() == tr("Bottom"))
    {
        x = w - x - fm.averageCharWidth() * ui->watermarkCharInputLabEd->text().length();
        y = h - y;
    }else
    {
        x = x;
        y = y + fm.ascent();
    }

    painter.drawText(x, y, ui->watermarkCharInputLabEd->text());

    qDebug()<< desImgFont.pixelSize();
    qDebug()<< "exit ImgProcessWatermark";

}

void MainWindow::ImgProcessReverser()
{
    if (!ui->reverseColorChk->checkState())
    {
        goto exit;
    }
    QRgb value;
    for (int dx=0; dx < desImg.width(); dx++)
    {
        for (int dy=0; dy < desImg.height(); dy++)
        {
            value = desImg.pixel(dx ,dy);
            int r = qRed(value);  int g = qGreen(value);
            int b = qBlue(value); int a = qAlpha(value);
            value = qRgba(0xff-r, 0xff-g, 0xff-b , 0xff-a);
            desImg.setPixel(dx, dy, value);

        }
    }
exit:
    qDebug()<< "exit ImgProcessReverser";
}

void MainWindow::ImgProcessBrightness()
{
    if (!ui->brightSlide->value())
    {
        goto exit;
    }
    QRgb value;
    for (int dx=0; dx < desImg.width(); dx++)
    {
    for (int dy=0; dy < desImg.height(); dy++)
        {
                value = desImg.pixel(dx ,dy);
                int r = qRed(value);
                int g = qGreen(value);
                int b = qBlue(value);
                int a = qAlpha(value);
                r = r + ui->brightSlide->value();
                g = g + ui->brightSlide->value();
                b = b + ui->brightSlide->value();

                if (r >= 255) {r = 255;} if (r <= 0) {r = 0;}
                if (g >= 255) {g = 255;} if (g <= 0) {g = 0;}
                if (b >= 255) {b = 255;} if (b <= 0) {b = 0;}
                if (a >= 255) {a = 255;} if (a <= 0) {a = 0;}

                value = qRgba(r , g , b, a);
                desImg.setPixel(dx, dy, value);

            }
        }
    exit:
    qDebug()<< "exit ImgProcessBrightness";
}

void MainWindow::ImgProcessBitsPixel()
{
    QRgb value;
    if (ui->ImgPixSel->currentText() == tr("monochrome"))
    {
        for (int dx=0; dx < desImg.width(); dx++)
         {
         for (int dy=0; dy < desImg.height(); dy++)
             {
                 value = desImg.pixel(dx ,dy);
                 int r = qRed(value);  int g = qGreen(value);
                 int b = qBlue(value); int a = qAlpha(value);
                 int avg = (r + g + b) /3;
                 int level;
                 level = 0xff/2;
                 avg = (int)((avg/level) * 0xff);
                 value = qRgba(avg , avg , avg, a);
                 desImg.setPixel(dx, dy, value);
             }
         }
    }else if (ui->ImgPixSel->currentText() == tr("24 bits TrueColor(R-G-B)"))
    {
        // TODO
        goto exit;
    }else if (ui->ImgPixSel->currentText() == tr("32 bits TrueColor(R-G-B-A)"))
    {
        //TODO
        goto exit;
    }
    exit:
    qDebug()<< "exit ImgProcessBrightness";
}

void MainWindow::on_reverseColorChk_clicked()
{
    ImgImport();
}

void MainWindow::on_rotationSel_activated(QString )
{
    ImgImport();
}

void MainWindow::on_brightSlide_valueChanged(int value)
{
    ui->brightLcd->display(value);
    ImgImport();
}

void MainWindow::on_DefaultBtn_clicked()
{

    ui->ImgWidthEd->setText(QString::number(srcImg.width()));
    ui->ImgHeightEd->setText(QString::number(srcImg.height()));

    ui->reverseColorChk->setChecked(0);
    ui->rotationSel->setCurrentIndex(0);
    ui->brightSlide->setValue(0);
    ui->brightLcd->display(0);
    ImgImport();
}

void MainWindow::on_ImgPixSel_activated(QString )
{
    ImgImport();
}
void MainWindow::ImgExport()
{
    QString ImgFilter;
    if (ui->ExportFormatSel->currentText() == tr("C array (*.c)"))
        ImgFilter = "C Array Files(*.c)";
    else if (ui->ExportFormatSel->currentText() == tr("BMP (*.bmp)"))
        ImgFilter = "Image Files(*.bmp)";
    else if (ui->ExportFormatSel->currentText() == tr("JPG (*.jpg)"))
        ImgFilter = "Image Files(*.jpg)";
    else if (ui->ExportFormatSel->currentText() == tr("PNG (*.png)"))
        ImgFilter = "Image Files(*.png)";
    else if (ui->ExportFormatSel->currentText() == tr("XMP (*.xmp)"))
        ImgFilter = "Image Files(*.xpm)";
    else
        qDebug() << tr("Unkmow file type") << endl;

    if (desFn.isEmpty())
        {
        desFn= QFileDialog::getSaveFileName(this,
                    "Save Image", QCoreApplication::applicationDirPath(), ImgFilter);
    }else{
        desFn= QFileDialog::getSaveFileName(this,
                    "Save Image", desFi.path(), ImgFilter);
    }
    desFile.setFileName(desFn);
    if (!desFile.open(QIODevice::WriteOnly))
    {
        QMessageBox::information(this, tr("info"), tr("Cannot open file for writing:"));
        goto exit;
    }
    desFi = desFn;

    if (ui->ExportFormatSel->currentText() == tr("C array (*.c)"))
    {
        ImgExporttoRawdata();
    }

    else if (desFi.suffix() == "bmp") { desImg.save(desFn, "BMP"); }
    else if (desFi.suffix() == "jpg") { desImg.save(desFn, "JPG"); }
    else if (desFi.suffix() == "png") { desImg.save(desFn, "PNG"); }
    else if (desFi.suffix() == "xpm") { desImg.save(desFn, "XPM"); }
    else{
        QMessageBox::information(this
                                 , tr("info")
                                 , tr("Unable to support this file foramt!"));
    }
    desFile.close();
    ui->statusBar->showMessage(tr("save to") + desFn + tr("done"), 2000);

    exit:
    qDebug()<< "exit ImgExport";
}
void MainWindow::ImgExporttoRawdata()
{
    raw_comment_1 = "/* Export from Pic2Lcd <http://code.google.com/p/pic2lcd/> */\n\n";
    raw_comment_2 = "/* Image Bits Pixel: */\n";
//  raw_comment_3 = "/* Raw-data format :R() G() B() A()                        */\n";

    raw_header = "const unsigned char Img_" + desFi.baseName() + "[]={\n";
    raw_tabtab = "\t\t";
    raw_endline = "\n";
    raw_space = "  ";
    raw_tail = "};";

    rawdata.clear();
    rawdata.append(raw_comment_1.toAscii().data());
//    rawdata.append(raw_comment_2.toAscii().data()+ ui->ImgPixSel->currentText() + "\n");
    rawdata.append(raw_header.toAscii().data());

    if (ui->ImgPixSel->currentText() == tr("monochrome"))
    {
        ImgExporttoMonochrome();
    }else if(ui->ImgPixSel->currentText() == tr("256 Color"))
    {
        // 8-bit(rrrgggbb) or Gray level
        ImgExportto256Color();
    }else if(ui->ImgPixSel->currentText() == tr("4096 Color"))
    {
        // 12-bit(rrrrggggbbbb-rrrrggggbbbb)
        ImgExportto4096Color();
    }else if(ui->ImgPixSel->currentText() == tr("24 bits TrueColor"))
    {
        // 24-bit(rrrrrrrrggggggggbbbbbbbb)
        ImgExportto24bits();
    }else if(ui->ImgPixSel->currentText() == tr("32 bits TrueColor"))
    {
        // 32-bit(rrrrrrrrggggggggbbbbbbbbaaaaaaaa)
        ImgExportto32bits();
    }


rawdata.append(raw_tail.toAscii().data());
desFile.write(rawdata);
}

void MainWindow::ImgExportto256Color()
{
    QRgb value;

    for (int dy=0; dy < desImg.height(); dy++)
            {
              for (int dx=0; dx < desImg.width(); dx++)
              {
                    unsigned char p=0;
                    value = desImg.pixel(dx ,dy);
                    int r = qRed(value); int g = qGreen(value); int b = qBlue(value);

                    if (ui->color256PaletteSel->currentText() == tr("RGB332 Palette"))
                    {
                        p = ((r & 0x07) << 5) + ((g & 0x07) << 2) + (b & 0x03);
                    }else
                    {
                        // Gray Palette(0xff:gray0/0x00:white)
                        p = (r + g + b)/3;
                    }
                    // export to 1 byte from 1 pixel(RGB888)
                    if (p <= 0xf){   rawdata.append("0x0" + QByteArray::number(p,16) + ","); }
                    else        {   rawdata.append("0x"  + QByteArray::number(p,16) + ","); }

                    if ((dx+1)%16==0 && dx!=0)
                    {
                        rawdata.append(" // (x:" + QByteArray::number(dx,10) +
                                       " y:" + QByteArray::number(dy,10) + ")" );
                        rawdata.append(raw_endline.toAscii().data());
                    }
                }
            }
}
void MainWindow::ImgExportto4096Color()
{
    QRgb value;
    unsigned int r1, g1, b1;
    unsigned int r2, g2, b2;
    unsigned char p1, p2, p3, p4;
    r1 = g1 = b1 = 0;
    r2 = g2 = b2 = 0;
    p1 = p2 = p3 = p4 = 0;
    unsigned int c = 0;     // TODO: unsigned long
    for (int dy=0; dy < desImg.height(); dy++)
            {
              for (int dx=0; dx < desImg.width(); dx++)
              {
                    value = desImg.pixel(dx ,dy);
                    // first pixel
                    if ((dy+1)*(dx+1)%2){ r1 = qRed(value); g1 = qGreen(value); b1 = qBlue(value); }
                    // second pixel
                    else                { r2 = qRed(value); g2 = qGreen(value); b2 = qBlue(value); }

                    //second pixel
                    if ((dy+1)*(dx+1)%2==0)
                    {
                        if (ui->color4096bit12rad->isChecked())             //RGB444
                        {
                            p1 = ((r1 & 0x0f) << 4) + ((g1 & 0x0f));        // rrrr-gggg
                            p2 = ((b1 & 0x0f) << 4) + ((r2 & 0x0f));        // bbbb-rrrr
                            p3 = ((g2 & 0x0f) << 4) + ((b2 & 0x0f));        // gggg-bbbb
                            c=c+3;
                        }else/* if (ui->color4096bit16rad->isChecked())*/
                        {
                            // Gray Palette(0xff:gray0/0x00:white)
                            p1 = r1 & 0x0f;                                 // 0000-rrrr
                            p2 = ((g1 & 0x0f) << 4) + ((b1 & 0x0f));        // gggg-bbbb
                            p3 = r2 & 0x0f;                                 // 0000-rrrr
                            p4 = ((g2 & 0x0f) << 4) + ((b2 & 0x0f));        // gggg-bbbb
                            c =c+4;
                        }

                        if (p1 <= 0xf){   rawdata.append("0x0" + QByteArray::number(p1,16) + ","); }
                        else          {   rawdata.append("0x"  + QByteArray::number(p1,16) + ","); }
                        if (p2 <= 0xf){   rawdata.append("0x0" + QByteArray::number(p2,16) + ","); }
                        else          {   rawdata.append("0x"  + QByteArray::number(p2,16) + ","); }
                        if (p3 <= 0xf){   rawdata.append("0x0" + QByteArray::number(p3,16) + ","); }
                        else          {   rawdata.append("0x"  + QByteArray::number(p3,16) + ","); }
                        if (!ui->color4096bit12rad->isChecked())
                        {
                            if (p4 <= 0xf){   rawdata.append("0x0" + QByteArray::number(p4,16) + ","); }
                            else          {   rawdata.append("0x"  + QByteArray::number(p4,16) + ","); }
                        }

                        if ((c%16==0) && c!=0)
                        {
                            rawdata.append(" // (c:" + QByteArray::number(c,10) + ")" );
                            rawdata.append(raw_endline.toAscii().data());
                        }
                    }
                }
          }
}

void MainWindow::ImgExporttoMonochrome()
{
    QRgb value;
    unsigned char p=0;
    for (int dy=0; dy < desImg.height(); dy++)
            {
              for (int dx=0; dx < desImg.width(); dx++)
              {
                    value = desImg.pixel(dx ,dy);
                    int r = qRed(value); int g = qGreen(value); int b = qBlue(value);

                    int avg = (r + g + b)/3;
                    if (avg >= 0x7f) { p = p + (1<<(dx%8)); }

                    // export to 1 byte from 8 pixel(RGB888)
                    if ((dx+1)%8== 0 && dx !=0)
                    {
                        //rawdata.append(" dx:" + QByteArray::number(dx,10) +
                        //               " dy:" + QByteArray::number(dy,10) + " :" );

                        if (p <= 0xf){   rawdata.append("0x0" + QByteArray::number(p,16) + ","); }
                        else        {   rawdata.append("0x"  + QByteArray::number(p,16) + ","); } 
                        p = 0;
                    }
                    if ((dx+1)%128==0 && dx!=0)
                    {
                        rawdata.append(raw_endline.toAscii().data());
                    }
            }
          }
}

void MainWindow::ImgExportto24bits()
{
#if 0
    QRgb *value;
    for (int x=0; x< desImg.byteCount(); x++)
    {
        value = (QRgb *)desImg.scanLine(x);
        int r = qRed(*value);
        int g = qGreen(*value);
        int b = qBlue(*value);
        rawdata.append(raw_tabtab.toAscii().data());

        if (r < 0xf){   rawdata.append("0x0" + QByteArray::number(r,16) + ","); }
        else        {   rawdata.append("0x"  + QByteArray::number(r,16) + ","); }
        if (g < 0xf){   rawdata.append("0x0" + QByteArray::number(g,16) + ","); }
        else        {   rawdata.append("0x"  + QByteArray::number(g,16) + ","); }
        if (b < 0xf){   rawdata.append("0x0" + QByteArray::number(b,16) + ","); }
        else        {   rawdata.append("0x"  + QByteArray::number(b,16) + ","); }

        rawdata.append(raw_endline.toAscii().data());
    }
#else
    QRgb value;
    for (int dx=0; dx < desImg.width(); dx++)
            {
              for (int dy=0; dy < desImg.height(); dy++)
              {
                value = desImg.pixel(dx ,dy);
                int r = qRed(value);
                int g = qGreen(value);
                int b = qBlue(value);
                rawdata.append(raw_tabtab.toAscii().data());

                if (r < 0xf){   rawdata.append("0x0" + QByteArray::number(r,16) + ","); }
                else        {   rawdata.append("0x"  + QByteArray::number(r,16) + ","); }
                if (g < 0xf){   rawdata.append("0x0" + QByteArray::number(g,16) + ","); }
                else        {   rawdata.append("0x"  + QByteArray::number(g,16) + ","); }
                if (b < 0xf){   rawdata.append("0x0" + QByteArray::number(b,16) + ","); }
                else        {   rawdata.append("0x"  + QByteArray::number(b,16) + ","); }

                rawdata.append(raw_endline.toAscii().data());
            }
        }
#endif
}
void MainWindow::ImgExportto32bits()
{
    QRgb value;
    for (int dx=0; dx < desImg.width(); dx++)
            {
              for (int dy=0; dy < desImg.height(); dy++)
              {
                value = desImg.pixel(dx ,dy);
                int r = qRed(value);   int g = qGreen(value);
                int b = qBlue(value);  int a = qAlpha(value);
                rawdata.append(raw_tabtab.toAscii().data());

                if (r < 0xf){   rawdata.append("0x0" + QByteArray::number(r,16) + ","); }
                else        {   rawdata.append("0x"  + QByteArray::number(r,16) + ","); }
                if (g < 0xf){   rawdata.append("0x0" + QByteArray::number(g,16) + ","); }
                else        {   rawdata.append("0x"  + QByteArray::number(g,16) + ","); }
                if (b < 0xf){   rawdata.append("0x0" + QByteArray::number(b,16) + ","); }
                else        {   rawdata.append("0x"  + QByteArray::number(b,16) + ","); }
                if (a < 0xf) { rawdata.append("0x0" + QByteArray::number(a,16) + ","); }
                else         { rawdata.append("0x"  + QByteArray::number(a,16) + ","); }
            }
            rawdata.append(raw_endline.toAscii().data());
    }
}


void MainWindow::on_desImgBtn_clicked()
{
    ImgExport();
}
void MainWindow::ActionDeliver(QAction *action)
{
    qDebug("action '%s' triggered", action->text().toLocal8Bit().data());
    if (action->text().toLocal8Bit().data() == tr("&Import"))
    {
        on_srcImgBtn_clicked();
    }
    else if (action->text().toLocal8Bit().data() == tr("&Export"))
    {
        on_desImgBtn_clicked();
    }
    else if (action->text().toLocal8Bit().data() == tr("&About"))
    {
        ShowAboutDialog();
    }
    else if (action->text().toLocal8Bit().data() == tr("&Diagnostic"))
    {
        ShowDiagnosticDialog();
    }
    else if (action->text().toLocal8Bit().data() == tr("&Contents"))
    {
        ShowContentsDialog();
    }
    qDebug()<< "exit ActionDeliver";
}

void MainWindow::ShowContentsDialog()
{
    contentsDialog.show();
}

void MainWindow::ShowDiagnosticDialog()
{
    diagnosticDialog.show();
}
void MainWindow::ShowAboutDialog()
{
    aboutDialog.show();
}

void MainWindow::on_watermarkSetBtn_clicked()
{
    ImgImport();
    qDebug()<< "exit on_watermarkSet_clicked";
}

void MainWindow::on_watermarkFontBtn_clicked()
{
    bool isOk;
    QLabel *tmpLab = new QLabel("<center>AaBbCc</center>");
    desImgFont = QFontDialog::getFont(&isOk, QFont("Verdana", 8, QFont::Bold), tmpLab);
    qDebug()<< "exit on_watermarkFontBtn_clicked";
}

void MainWindow::on_watermarkColorBtn_clicked()
{
    QColorDialog::setCustomColor(0, QRgb(0x0000FF));
    desImgFontColor = QColorDialog::getColor(QColor(0, 255, 0));

#if (0)
    if(color.isValid()) {
        text.sprintf("R: %d G: %d B: %d",
                     color.red(), color.green(), color.blue());
        QMessageBox::information(0, "Selected color",
             text, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
    }

    text.sprintf("Available custom colors: %d", QColorDialog::customCount());
    QMessageBox::information(0, "Get Selected Color",
             text, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
#endif
    qDebug()<< "exit on_watermarkColorBtn_clicked";
}
